package me.zhengjie.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.pojo.dto.*;
import me.zhengjie.pojo.vo.AgvTaskSubmitVo;
import me.zhengjie.pojo.vo.ReturnVo;
import me.zhengjie.service.AgvReturnService;
import me.zhengjie.service.InterfaceService;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/wcs")
@RequiredArgsConstructor
@Api(tags = "wcs接口")
public class InterfaceController {

    private final InterfaceService interfaceService;

    private final AgvReturnService agvReturnService;

    //查询流利架当前模式
    @ApiOperation(("查询流利架模式"))
    @GetMapping("/interface/fluentFrame/mode")
    public ReturnVo fluentFrameMode(HttpServletRequest request){
        ReturnVo returnVo = interfaceService.fluentFrameMode(request);
        return returnVo;
    }

    @ApiOperation(("修改流利架模式"))
    @GetMapping("/interface/update/{mode}")
    public ReturnVo updateMode(HttpServletRequest request, @PathVariable Integer mode){
        ReturnVo returnVo = interfaceService.updateMode(request,mode);
        return returnVo;
    }

    @ApiOperation(("查询空料箱"))
    @GetMapping("/query/empty/material/box/{page}/{size}")
    public ReturnVo queryEmptyMaterialBox(HttpServletRequest request, @PathVariable Integer page ,@PathVariable Integer size){
        ReturnVo returnVo = interfaceService.queryEmptyMaterialBox(request,page,size);
        return returnVo;
    }


    @ApiOperation(("扫码获取左右二边读码信息"))
    @PostMapping("/sweep/storage")
    public ReturnVo sweepStorage(HttpServletRequest request, @RequestBody SweepStorageDto sweepStorageDto){
        ReturnVo returnVo = interfaceService.sweepStorage(request,sweepStorageDto);
        return returnVo;
    }

    @ApiOperation(("任务强制完成"))
    @GetMapping("/task/force/complete/{taskCode}")
    public ReturnVo taskForceComplete(@PathVariable String taskCode){
        AgvReturnDto agvReturnDto = new AgvReturnDto();
        agvReturnDto.setRobotTaskCode(taskCode);
        Extra extra = new Extra();
        Values values = new Values();
        values.setMethod("outbin");
        extra.setValues(values);
        extra.setValues(values);
        agvReturnDto.setExtra(extra);
        AgvTaskSubmitVo agvTaskSubmitVo = agvReturnService.agvTaskReport(agvReturnDto);
        Extra extra1 = agvReturnDto.getExtra();
        Values values1 = extra1.getValues();
        values1.setMethod("end");
        AgvTaskSubmitVo agvTaskSubmitVos = agvReturnService.agvTaskReport(agvReturnDto);
        if ("SUCCESS".equals(agvTaskSubmitVo.getCode()) && "SUCCESS".equals(agvTaskSubmitVos.getCode())){
            return ReturnVo.OK();
        }
        return ReturnVo.ng("强制取消失败，数据异常");
    }

    @ApiOperation(("查询楼层所有储位"))
    @GetMapping("/query/{floor}")
    public ReturnVo queryFloor(@PathVariable String floor){
        ReturnVo returnVo = interfaceService.queryFloor(floor);
        return returnVo;
    }

    @ApiOperation(("提交空托盘数量"))
    @PostMapping("/empty/tray/quantity")
    public ReturnVo emptyTrayQuantity(@RequestBody EmptyTrayQuantityDto emptyTrayQuantityDto){
        ReturnVo returnVo = interfaceService.emptyTrayQuantity(emptyTrayQuantityDto);
        return returnVo;
    }

    @ApiOperation(("线边仓储位禁用与释放"))
    @PostMapping("/line/edge/warehouse/modify")
    public ReturnVo lineEdgeWarehouseModify(@RequestBody LineEdgeWarehouseModifyDto lineEdgeWarehouseModifyDto){
        ReturnVo returnVo = interfaceService.lineEdgeWarehouseModify(lineEdgeWarehouseModifyDto);
        return returnVo;
    }

    @ApiOperation(("楼层查询可用储位"))
    @GetMapping("/query/available")
    public ReturnVo queryAvailableFloor(@RequestParam(defaultValue = "") String floor) {
        ReturnVo returnVo = interfaceService.queryAvailableFloor(floor);
        return returnVo;
    }

    @ApiOperation(("查询所有楼层"))
    @GetMapping("/query/floor/all")
    public ReturnVo queryFloorAll() {
        ReturnVo returnVo = interfaceService.queryFloorAll();
        return returnVo;
    }

    @ApiOperation(("流利架NG信息查询"))
    @GetMapping("/fluent/frame/ng")
    public ReturnVo fluentFrameNg(HttpServletRequest request) {
        ReturnVo returnVo = interfaceService.fluentFrameNg(request);
        return returnVo;
    }

    @ApiOperation(("流利架查询分拣区箱号查询"))
    @GetMapping("/fluent/frame/outbound")
    public ReturnVo fluentFrameOutbound(HttpServletRequest request) {
        ReturnVo returnVo = interfaceService.fluentFrameOutbound(request);
        return returnVo;
    }
}
